<template>
	<view class="authenticate">
		<view class="header">
			<text class="h_title">{{ dataInfo.diseaseName || '案例详情' }}</text>
			<text>发布者：{{ this.$replaceLastStr(dataInfo.ownerUserName) || this.$replaceLastStr(this.$storage.getItem('roleDataInfo').name) }}</text>
		</view>
		<view class="column main">
			<van-cell-group>
				<van-cell required title="康复疾病" :value="dataInfo.diseaseName" />
				<van-cell required title="康复后是否复发" :value="dataInfo.isRecurs == '1' ? '是' : '否'" />
				<van-field
					class="column"
					label="治疗手段及方法"
					title-width="240rpx"
					clearable
					required
					readonly
					type="textarea"
					:autosize=" { minHeight: '60px' }"
				  :value="dataInfo.cureProcess"
				  :border="false"
				/>
				<van-field
					clearable
					readonly
					class="upLoad"
				>
					<template slot="button" class="upLoadOn">
						<view class="upLoadTitle">附件</view>
						<van-uploader :show-upload='false' :deletable="false" :file-list="dataInfo.cureProcessFilesName"></van-uploader>
					</template>
				</van-field>
			</van-cell-group>
			
			<van-cell-group v-if="dataInfo.diseaseDescFilesName.length || dataInfo.medicalHistoryFilesName.length || dataInfo.diseaseDesc || dataInfo.medicalHistory">
				<van-cell
					class="bigTitle"
					title="专业康复检查（附体检报告）"
					label-class="title"
					readonly
				/>
				<template v-if="dataInfo.diseaseDescFilesName.length || dataInfo.diseaseDesc">
					<van-field
						class="column textarea"
						label="康复前后身体情况描述（照片、X光、CT片）"
						title-width="600rpx"
						clearable
						readonly
						:value="dataInfo.diseaseDesc"
						type="textarea"
						:autosize=" { minHeight: '60px' }"
						maxlength="2000"
						:border="false"
					/>
					<van-field
						v-if="dataInfo.diseaseDescFilesName.length"
						clearable
						readonly
						class="upLoad"
					>
						<template slot="button" class="upLoadOn">
							<view class="upLoadTitle">附件</view>
							<van-uploader :show-upload='false' :deletable="false" :file-list="dataInfo.diseaseDescFilesName"></van-uploader>
						</template>
					</van-field>
				</template>
				<template v-if="dataInfo.medicalHistoryFilesName.length || dataInfo.medicalHistory">
					<van-field
						class="column textarea"
						label="以往病史"
						title-width="450rpx"
						clearable
						readonly
						:value="dataInfo.medicalHistory"
						type="textarea"
						:autosize=" { minHeight: '60px' }"
						maxlength="2000"
						:border="false"
					/>
					<van-field
						v-if="dataInfo.medicalHistoryFilesName.length"
						clearable
						readonly
						class="upLoad"
					>
						<template slot="button" class="upLoadOn">
							<view class="upLoadTitle">附件</view>
							<van-uploader :show-upload='false' :deletable="false" :file-list="dataInfo.medicalHistoryFilesName"></van-uploader>
						</template>
					</van-field>
				</template>
			</van-cell-group>
			
			<van-cell-group v-if="status != 2">
				<van-cell
					class="bigTitle"
					title="核实情况"
					label-class="title"
					readonly
					:border="false"
				/>
				<van-field
					class="column textarea"
					placeholder="请输入需要核实的内容"
					title-width="300rpx"
					clearable
					:readonly="status != 1"
					type="textarea"
					:autosize=" { minHeight: '60px' }"
				  :value="dataValue1.verifyContent"
				  maxlength="2000"
				  :border="false"
					@input="blur('verifyContent', $event)"
				/>
				<template v-if="status == 1">
					<van-cell
						class="bigTitle"
						title="是否上鉴定会"
						label-class="title"
						readonly
						:border="false"
					/>
					<view class="pbulish" style="padding-top: 20rpx; background-color:#FFFFFF;">
						<van-radio-group class="radioGroup" :value="dataValue1.isAudit"  @change="pubChange($event)">
						  <van-radio name="1" checked-color="#02BF88">同意上鉴定会</van-radio>
						  <van-radio name="0" style="margin-left: 60rpx;" checked-color="#02BF88">不同意上鉴定会</van-radio>
						</van-radio-group>
					</view>
				</template>
				<template v-if="status == 3">
					<van-cell
						class="bigTitle"
						:title="dataInfo.status == 3 ?'已核实，可以上鉴定会' : '已核实，不可以上鉴定会'"
						label-class="title"
						readonly
						:border="false"
					/>
				</template>
			</van-cell-group>
		</view>
		<template v-if="status == 1">
			<view class="commonBtnBox btnBox">
				<van-button type="primary" round @click="confim('success')">完成</van-button>
			</view>
		</template>
<!-- 		<template v-if="status == 3">
			<view class="commonBtnBox btnBox">
				<van-button type="primary" round @click="identify">去鉴定</van-button>
			</view>
		</template> -->
		<van-toast id='van-toast'/>
	</view>
</template>

<script>
	import { fileById } from '@/api/common'
	import { finishedAppraisal, auditCase } from '@/api/my'
	import { pubGetId } from '@/api/case'
	import { formValidation } from '@/utils/regexp'
	export default {
		name: 'authenticate',
		data() {
			return {
				status: 1,
				dataValue1: {
					verifyContent: '',
					isAudit: '1'
				},
				rules1: {
					verifyContent: [
						{ required: true, message: '请输入需要核实的内容' }
					]
				},
				dataInfo: {}
			}
		},
		onLoad(option) {
			this.getDataInfo(option.id);
			this.status = option.status;
		},
		methods: {
			blur(e,s) {
				this.dataValue1[e] = s.detail;
			},
			getDataInfo(id) {
				pubGetId({ id: id }).then(res => {
					this.dataInfo = res.data;
					let sex = '';
					if (this.dataInfo.gender == 0) {
						sex = '保密'
					} else if (this.dataInfo.gender == 1) {
						sex = '男'
					} else {
						sex = '女'
					}
					this.$set(this.dataInfo,'sex',sex);
					if (res.data.cureProcessFiles.length) {
						this.getFile(res.data.cureProcessFiles,'cureProcessFilesName')
					}
					if (res.data.diseaseDescFiles.length) {
						this.getFile(res.data.diseaseDescFiles,'diseaseDescFilesName')
					}
					if (res.data.medicalHistoryFiles.length) {
						this.getFile(res.data.medicalHistoryFiles,'medicalHistoryFilesName')
					}
					if (res.data.verifyContent) {
						this.dataValue1.verifyContent = res.data.verifyContent
					}
				})
			},
		  getFile(val,typeName) {
				let arr = [];
				val.map(item => {
				  fileById({ fileId: item }).then(res => {
						if (res.data && res.data.accessUrl) {
							arr.push({ url: res.data.accessUrl })
						}
					})
				})
				this.$set(this.dataInfo,typeName, arr);
			},
			confim(mode) {
				if (mode == 'success') {
					this.$set(this.dataValue1,'caseId', this.dataInfo.id);
					formValidation({
						data: this.dataValue1,
						rules: this.rules1
					}).then(res => {
						this.$showModal({
							title: '提示',
							content: '是否鉴定该康复案例？',
							showCancel: true,
						}, (suc) => {
							auditCase(this.dataValue1).then(red => {
								if (red.status == 1) {
									this.$toast.success(red.message);
									setTimeout(() => {
										uni.navigateBack();
									}, 1600)
								} else {
									this.$toast.fail(red.message);
								}
							})
						})
					})
				} else {
					uni.navigateBack();
				}
			},
			// 去鉴定
			identify() {
				console.log('可以鉴定')
			},
			// 是否发布
			pubChange(e) {
				this.dataValue1.isAudit = e.detail
			}
		}
	}
</script>

<style lang="scss" scoped>
	.authenticate {
		width: 100%;
		position: relative;
		padding: 0 20rpx 140rpx;
		box-sizing: border-box;
		background-color: #F8F8F8;
		min-height: 100vh;
		.header {
			padding: 24rpx 0 16rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			text {
				font-size: 28rpx;
				color: #666666;
			}
			.h_title {
				font-size: 32rpx;
				text-align: center;
				font-weight: 600;
				color: #333333;
			}
		}
		.main {
			width: 100%;
			/deep/ .van-cell__title {
				color: #333333;
				font-size: 32rpx;
			}
			/deep/ .van-cell__value {
				color: #666666;
				text-align: left;
				font-size: 28rpx;
			}
			.bigTitle {
				/deep/ .van-cell {
					padding-left: 10rpx;
				}
				/deep/ .van-cell__title {
					color: #333333;
					font-size: 32rpx;
				}
			}
			.textarea {
				/deep/ .van-cell__value {
					background-color: #F7F8FA;
					border-radius: 16rpx;
					padding: 16rpx;
				}
			}
			.upLoad /deep/ .van-field__input {
				display: none;
			}
			/deep/ .van-field__button {
				padding-left: 0;
			}
			.radioGroup {
				display: flex;
				padding-left: 10rpx;
				padding-bottom: 44rpx;
			}
		}
		.btnBox {
			color: #FFFFFF;
			padding: 20rpx 0;
			background-color: #FFFFFF;
			box-sizing: border-box;
			margin-bottom: 0;
		}
		/deep/ .van-field__input--textarea {
			color: #666666;
		}
	}
	.upLoadOn {
		text-align: left;
		.upLoadTitle {
			color: #333333;
			font-size: 32rpx;
		}
		/deep/ .van-button--normal {
			padding: 90rpx 80rpx;
		}
	}
</style>
